home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 751-760 / 753 / askfirst / askfirst.s < prev    next >
Text File  |  1995-03-18  |  10KB  |  489 lines

  1.  ;AskFirst.By Kamran Karimi.It is a software disk protection mechanism
  2.  ;and when asked by the user prevents writes on a write-enabled disk
  3.  ;assembled with Cape Assembler
  4.  
  5.  
  6.  
  7. ExecBase equ 4
  8. FindTask equ -294
  9. OpenLib equ -408
  10. CloseLib equ -414
  11. OpenWindow equ -204
  12. CloseWindow equ -72
  13. WaitPort equ -384
  14. GetMsg equ -372
  15. ReplyMsg equ -378
  16. PrintIText equ -216
  17. Allocmem equ -198
  18. FreeMem equ -210
  19. Forbid equ -132
  20. Permit equ -138
  21. Delay equ -198
  22. DoIO equ -454
  23. SendIO equ -460
  24.  
  25.           
  26.  
  27.  
  28. Start:
  29.  movem.l d0/a0,-(a7)       ;save command line parameters
  30.  move.l  #20,d6         ;possible return code to DOS
  31.  move.l  ExecBase,a6
  32.  movea.l #0,a1
  33.  jsr     FindTask(a6)
  34.  move.l  d0,a4
  35.  tst.l   $ac(a4)
  36.  bne     FromCLI
  37.  
  38. FromWorkBench:        ;get workbench message
  39.  lea     $5c(a4),a0
  40.  jsr     WaitPort(a6)
  41.  lea     $5c(a4),a0
  42.  jsr     GetMsg(a6)
  43.  bra     StackAdjust
  44.  
  45. FromCLI:
  46.  movem.l (a7)+,d0/a0  ;command line parameters
  47.  subq    #1,d0
  48.  beq     NoParam
  49.  
  50. LoopParam1:
  51.  cmpi.b  #' ',(a0)+
  52.  bne     Found
  53.  dbra    d0,LoopParam1
  54.  bra     NoParam
  55. Found:
  56.  suba.l  #1,a0
  57.  cmpi.b  #'n',(a0)
  58.  beq     FoundN
  59.  cmpi.b  #'N',(a0)
  60.  bne     NoParam
  61. FoundN:
  62.  adda.l  #1,a0
  63.  cmpi.b  #'o',(a0)
  64.  beq     FoundO
  65.  cmpi.b  #'O',(a0)
  66.  bne     NoParam
  67. FoundO:
  68.  move.w  #$86,SelAddr
  69.  move.l  #0,AllowedD    ;found no in the command line so don't allow
  70.  move.l  #0,AllowedS
  71.  bra     NoParam
  72.  
  73. StackAdjust:
  74.  movem.l (a7)+,d0/a0
  75. NoParam:
  76.  moveq   #0,d5          ;flag for In Effect/Not In Effect determination
  77.  lea     DOSName,a1
  78.  jsr     OpenLib(a6)
  79.  move.l  d0,DOSBase
  80.  beq     NoDOS
  81.  lea     IntuitionName,a1
  82.  jsr     OpenLib(a6)
  83.  move.l  d0,IntBase
  84.  beq     NoIntuition
  85.  move.l  d0,a6
  86.  lea     WindowParam,a0
  87.  jsr     OpenWindow(a6)
  88.  move.l  d0,WindowHandler
  89.  beq     NoWindow
  90.  move.l  WindowHandler,a0
  91.  move.l  50(a0),a0
  92.  lea     MyName,a1
  93.  move.l  #4,d0
  94.  move.l  #12,d1
  95.  jsr     PrintIText(a6)
  96.  move.l  DOSBase,a6
  97.  move.l  #100,d1
  98.  jsr     Delay(a6)
  99.  move.l  IntBase,a6
  100.  move.l  WindowHandler,a0
  101.  jsr     CloseWindow(a6)
  102.  move.l  #MyGadget,GadAddr
  103.  lea     WindowParam,a0
  104.  jsr     OpenWindow(a6)
  105.  move.l  d0,WindowHandler
  106.  beq     NoWindow
  107.  move.l  WindowHandler,a0
  108.  move.l  50(a0),a0
  109.  lea     MyText,a1
  110.  move.l  #4,d0
  111.  move.l  #12,d1
  112.  jsr     PrintIText(a6)
  113.  move.l  ExecBase,a6
  114.  move.l  #EndeDoIO-BeginDoIO,d0
  115.  move.l  #$10000,d1
  116.  jsr     Allocmem(a6)
  117.  move.l  d0,ReservedDoIO   ;the address where we will copy the DoIO routine
  118.  beq     NoMem
  119.  move.l  #EndeSendIO-BeginSendIO,d0
  120.  jsr     Allocmem(a6)
  121.  move.l  d0,ReservedSendIO    ;same as above for SendIO
  122.  beq     FreeDoIO
  123.  
  124.  move.l  DoIO(a6),SaveDoIO      ;save original vectors
  125.  move.l  DoIO(a6),MySaveDoIO
  126.  move.l  SendIO(a6),SaveSendIO
  127.  move.l  SendIO(a6),MySaveSendIO
  128.  
  129.  move.l  #BeginDoIO,a0
  130.  move.l  ReservedDoIO,a1
  131.  move.l  #EndeDoIO-BeginDoIO,d0
  132.  subi.l  #1,d0
  133. loop1:                          ;copy the routines to the allocated mem
  134.  move.b  (a0)+,(a1)+
  135.  dbra    d0,loop1
  136.  move.l  #BeginSendIO,a0
  137.  move.l  ReservedSendIO,a1
  138.  move.l  #EndeSendIO-BeginSendIO,d0
  139.  subi.l  #1,d0
  140. loop2:
  141.  move.b  (a0)+,(a1)+
  142.  dbra    d0,loop2
  143.  
  144.  jsr     Forbid(a6)                ;change vectors with ours
  145.  move.l  ReservedSendIO,SendIO(a6)
  146.  move.l  ReservedDoIO,DoIO(a6) 
  147.  jsr     Permit(a6)
  148.  moveq   #0,d7      ; flag to show that no diskchange has occured
  149.          ;so that befor the first diskchange nothing is written(In Eff...)
  150.  
  151. WaitOn:                     ;this is the main loop
  152.  move.l  WindowHandler,a0
  153.  move.l  86(a0),d4
  154.  move.l  d4,a0
  155.  jsr     WaitPort(a6)
  156.  move.l  d4,a0
  157.  jsr     GetMsg(a6)
  158.  move.l  d0,a0
  159.  move.l  20(a0),d6
  160.  move.l  d0,a1
  161.  jsr     ReplyMsg(a6)
  162.  cmpi.l  #$200,d6        ;Windowclose
  163.  beq     Quit
  164.  cmpi.l  #$8000,d6       ;diskinserted
  165.  beq     DiskInserted
  166.  
  167. GadgetChosen:
  168.  move.w  SelAddr,d6
  169.  andi.w  #$80,d6       ;SELECTED?
  170.  beq     Allow
  171.  moveq   #0,d2      ;value in d2 is used to enable/disable writing
  172.  bra     Enforce
  173. Allow:
  174.  moveq   #1,d2
  175.  
  176. Enforce:
  177.  jsr     Forbid(a6)
  178.  movea.l ReservedDoIO,a0
  179.  move.l  #AllowedD-BeginDoIO,d1
  180.  adda.l  d1,a0               ;a0 contains the address of the Allowedx
  181.  movem.l d2,(a0)
  182.  movea.l ReservedSendIO,a0
  183.  move.l  #AllowedS-BeginSendIO,d1
  184.  adda.l  d1,a0
  185.  movem.l d2,(a0)
  186.  jsr     Permit(a6)
  187.  move.l  IntBase,a6
  188.  tst.l   d7
  189.  beq     L1
  190.  tst.l   d5
  191.  bne     NEffe
  192.  subi.l  #1,d3
  193.  bne     L1
  194.  moveq   #2,d3
  195.  move.l  WindowHandler,a0
  196.  move.l  50(a0),a0
  197.  lea     InEffect,a1
  198.  move.l  #0,d0
  199.  move.l  #0,d1
  200.  jsr     PrintIText(a6)
  201. L1:
  202.  move.l  Execbase,a6
  203.  moveq   #1,d5
  204.  Bra     WaitOn
  205. NEffe:
  206.  sub.l   #1,d3
  207.  move.l  WindowHandler,a0
  208.  move.l  50(a0),a0
  209.  lea     NotInEffect,a1
  210.  move.l  #0,d0
  211.  move.l  #0,d1
  212.  jsr     PrintIText(a6)
  213.  move.l  Execbase,a6
  214.  moveq   #0,d5
  215.  bra    WaitOn
  216.  
  217. DiskInserted:
  218.  moveq   #1,d7
  219.  move.l  IntBase,a6
  220.  move.l  WindowHandler,a0
  221.  move.l  50(a0),a0
  222.  lea     InEffect,a1
  223.  move.l  #0,d0
  224.  move.l  #0,d1
  225.  jsr     PrintIText(a6)
  226.  move.l  Execbase,a6
  227.  moveq   #1,d5
  228.  moveq   #2,d3
  229.  bra     WaitOn
  230.  
  231. Quit:
  232.  moveq  #0,d6
  233.  move.l ExecBase,a6
  234.  move.l MySaveDoIO,DoIO(a6)
  235.  move.l MySaveSendIO,SendIO(a6) 
  236.  move.l ReservedSendIO,a1
  237.  move.l #EndeSendIO-BeginSendIO,d0
  238.  jsr    FreeMem(a6)
  239.  
  240. FreeDoIO:
  241.  move.l ReservedDoIO,a1
  242.  move.l #EndeDoIO-BeginDoIO,d0
  243.  jsr    FreeMem(a6)  
  244.  
  245. NoMem:
  246.  move.l IntBase,a6
  247.  move.l WindowHandler,a0
  248.  jsr    CloseWindow(a6)
  249.  
  250. NoWindow:
  251.  move.l ExecBase,a6
  252.  move.l IntBase,a1
  253.  jsr    CloseLib(a6)
  254.  
  255. NoIntuition:
  256.  move.l ExecBase,a6
  257.  move.l DOSBase,a1
  258.  jsr    CloseLib(a6)
  259. NoDOS:
  260.  move.l d6,d0
  261.  rts
  262.  
  263.  
  264. IntuitionName:  dc.b 'intuition.library',0
  265. DOSName:        dc.b 'dos.library',0
  266. ReservedDoIO:   dc.l 0
  267. ReservedSendIO: dc.l 0
  268. WindowHandler:  dc.l 0
  269. IntBase:        dc.l 0
  270. DOSBase:        dc.l 0
  271. MySaveDoIO:     dc.l 0
  272. MySaveSendIO:   dc.l 0
  273.  
  274. MyText:         dc.b 1,0,1,0
  275.                 dc.w 1,0
  276.                 dc.l 0
  277.                 dc.l Texte
  278.                 dc.l 0
  279. Texte:          dc.b 'Allow Floppy Writes?',0,0
  280.  
  281. InEffect:       dc.b 3,0,1,0
  282.                 dc.w 20,27
  283.                 dc.l 0
  284.                 dc.l IEText
  285.                 dc.l 0
  286. IEText:         dc.b 'In Effect:    ',0,0
  287.  
  288. NotInEffect:    dc.b 3,0,1,0
  289.                 dc.w 20,27
  290.                 dc.l 0
  291.                 dc.l NIEText
  292.                 dc.l 0
  293. NIEText:        dc.b 'Not In Effect!',0,0
  294.  
  295.  
  296. MyName:         dc.b 2,0,1,0
  297.                 dc.w 35,4
  298.                 dc.l 0
  299.                 dc.l Name1
  300.                 dc.l MyName2
  301. Name1:          dc.b '   Ask First!',0
  302.  
  303. MyName2:        dc.b 1,0,1,0
  304.                 dc.w 35,16
  305.                 dc.l 0
  306.                 dc.l Name2
  307.                 dc.l 0
  308. Name2:         dc.b 'By Kamran Karimi',0,0
  309.  
  310.  
  311. WindowParam:
  312.  dc.w 10
  313.  dc.w 5
  314.  dc.w 200
  315.  dc.w 40
  316.  dc.b -1
  317.  dc.b -1
  318.  dc.l $8220
  319.  dc.l $e
  320. GadAddr:
  321.  dc.l 0
  322.  dc.l 0
  323.  dc.l WindowName
  324.  dc.l 0
  325.  dc.l 0
  326.  dc.w 0
  327.  dc.w 0
  328.  dc.w 0
  329.  dc.w 0
  330.  dc.w 1
  331.  
  332. WindowName: dc.b 'AskFirst',0,0
  333.  
  334. MyGadget:
  335.  dc.l 0
  336.  dc.w 150
  337.  dc.w 23
  338.  dc.w 32
  339.  dc.w 13
  340. SelAddr:
  341.  dc.w $6       ;Flags
  342.  dc.w $102     ;activation
  343.  dc.w 1
  344.  dc.l ImOK
  345.  dc.l ImNO
  346.  dc.l 0
  347.  dc.l 0
  348.  dc.l 0
  349.  dc.w 1
  350.  dc.l 0
  351.  
  352. ImOK:
  353.  dc.w 0,0,32,13
  354.  dc.w 1
  355.  dc.l ImOKData
  356.  dc.b 2,1
  357.  dc.l 0
  358.  
  359. ImOKData:
  360.  dc.l %00000000000000000000000000000000
  361.  dc.l %00001111111000000111100011100000
  362.  dc.l %00111000001110000011100011100000
  363.  dc.l %00111000001110000011100111000000
  364.  dc.l %00111000001110000011101110000000
  365.  dc.l %00111000001110000011111100000000
  366.  dc.l %00111000001110000011111100000000
  367.  dc.l %00111000001110000011100111000000
  368.  dc.l %00111000001110000011100011100000
  369.  dc.l %00111000001110000011100001110000
  370.  dc.l %00111000001110000011100001110000
  371.  dc.l %00001111111000000111100001110000
  372.  dc.l %00000000000000000000000000000000
  373.  
  374. ImNO:
  375.  dc.w 0,0,32,13
  376.  dc.w 1
  377.  dc.l ImNOData
  378.  dc.b 2,1
  379.  dc.l 0
  380.  
  381. ImNOData:
  382.  dc.l %00000000000000000000000000000000
  383.  dc.l %00111000000011100000111111100000
  384.  dc.l %00111100000011100011100000111000
  385.  dc.l %00111111000011100011100000111000
  386.  dc.l %00111011100011100011100000111000
  387.  dc.l %00111001110011100011100000111000
  388.  dc.l %00111000111011100011100000111000
  389.  dc.l %00111000011111100011100000111000
  390.  dc.l %00111000001111100011100000111000
  391.  dc.l %00111000000111100011100000111000
  392.  dc.l %00111000000011100011100000111000
  393.  dc.l %00111000000011100000111111100000
  394.  dc.l %00000000000000000000000000000000
  395.  
  396.  
  397. BeginDoIO:
  398.  movem.l d0/a0/a1/a2/a3/a4,-(a7)
  399.  move.l  20(a1),a2      ;device
  400.  move.l  10(a2),a3       ;device name
  401.  move.l  #15,d0
  402.  lea     TrackNameD(pc),a4
  403. lop2D:
  404.  cmpm.b  (a3)+,(a4)+
  405.  bne     EnditD          ;is it trackdisk.sevice
  406.  dbra    d0,lop2D
  407.  move.w  28(a1),d0         ;d0 has command
  408.  andi.w  #$00ff,d0
  409.  cmpi.w  #15,d0       ;ask for protection?
  410.  beq     WriteD
  411.  bra     EnditD
  412.  
  413. WriteD:
  414.  move.l  AllowedD(pc),d0
  415.  tst.l   d0                          ;allow write?
  416.  beq     NoWriteD
  417.  
  418. EnditD:
  419.  movem.l (a7)+,d0/a0/a1/a2/a3/a4
  420.  move.l  SaveDoIO(pc),-(a7)          ;cintinue normally
  421.  rts
  422.  
  423. NoWriteD:
  424.  movem.l (a7)+,d0/a0/a1/a2/a3/a4
  425.  suba.l  #4,a7
  426.  move.l  a1,-(a7)
  427.  lea     AddressD(pc),a1
  428.  move.l  a1,4(a7)
  429.  move.l  (a7)+,a1
  430.  move.l  SaveDoIO(pc),-(a7)      ;continue routine
  431.  rts
  432. AddressD:
  433.  move.b  #$ff,32(a1)        ;back from DoIO,now change the result!
  434.  rts                      ;return to main program
  435.  
  436. SaveDoIO:   dc.l 0
  437. AllowedD:   dc.l 1
  438. TrackNameD: dc.b 'trackdisk.device',0,0
  439. EndeDoIO:
  440.  
  441.  
  442.  
  443. BeginSendIO:
  444.  movem.l d0/a0/a1/a2/a3/a4,-(a7)
  445.  move.l  20(a1),a2    ;device pointer
  446.  move.l  10(a2),a3    ;device name
  447.  move.l  #15,d0
  448.  lea     TrackNameS(pc),a4
  449. lop2S:
  450.  cmpm.b  (a3)+,(a4)+
  451.  bne     EnditS            ;is it trackdisk.device?
  452.  dbra    d0,lop2S
  453.  move.w  28(a1),d0         ;d0 has command
  454.  andi.w  #$00ff,d0
  455.  cmpi.w  #15,d0
  456.  beq     WriteS
  457.  bra     EnditS
  458.  
  459. WriteS:
  460.  move.l  AllowedS(pc),d0
  461.  tst.l   d0
  462.  beq     NoWriteS
  463.  
  464. EnditS:
  465.  movem.l (a7)+,d0/a0/a1/a2/a3/a4
  466.  move.l  SaveSendIO(pc),-(a7)
  467.  rts
  468.  
  469. NoWriteS:
  470.  movem.l (a7)+,d0/a0/a1/a2/a3/a4
  471.  suba.l  #4,a7
  472.  move.l  a1,-(a7)
  473.  lea     AddressS(pc),a1
  474.  move.l  a1,4(a7)
  475.  move.l  (a7)+,a1
  476.  move.l  SaveSendIO(pc),-(a7)
  477.  rts
  478. AddressS:
  479.  move.b  #$ff,32(a1)
  480.  rts
  481.  
  482. SaveSendIO:   dc.l 0
  483. AllowedS:     dc.l 1
  484. TrackNameS:   dc.b 'trackdisk.device',0,0
  485. EndeSendIO:
  486.  
  487.  end
  488.  
  489.